import axios from 'axios'
import Cookies from 'js-cookie'  

const http = axios.create({
  baseURL: '',
  timeout: 1000 * 180,
  withCredentials: true
})

/**
 * 请求拦截
 */
http.interceptors.request.use(config => {
  config.headers['Accept-Language'] = Cookies.get('language') || 'zh-CN'
  if (config.url !== '/oauth/token') {
    config.headers['Authorization'] = 'Bearer ' + Cookies.get('access_token') || ''
  }
  
  return config
}, error => {
  return Promise.reject(error)
})

/**
 * 响应拦截
 */
http.interceptors.response.use(response => {
  
  return response
}, error => {
  console.error(error)
  return Promise.reject(error)
})

export default http
